#ifndef __SCHEDULER_H
#define __SCHEDULER_H

/* processor status */
typedef struct ProcStatus_S
{
  pthread_mutex_t lock;
  pthread_barrier_t bar;
  long num_proc;
  unsigned long running;
} ProcStatus_T;
typedef ProcStatus_T * ProcStatus;

/* processor arguments */
typedef struct ProcArgs_S
{
  long tid;
  Fifo * fifo;
  ProcStatus pstat;
} ProcArgs_T;
typedef ProcArgs_T * ProcArgs;

/* work unit */
typedef struct Work_S
{
  void (*routine)(void *);
  void * input;
} Work_T;
typedef Work_T * Work;
 
/* prototypes */

void schedule (Fifo * f, long nt, void (*routine)(void *), void * arg);
void terminateProcessors (Fifo * f, int num_thread);
void * processor (void * input);
void launchProcessors(int num_proc, pthread_t threads[], ProcStatus pstat, ProcArgs pargs, Fifo * f);
void collectProcessors(int num_proc, pthread_t threads[], ProcStatus pstat);

#endif
